package cn.techjc.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 */ 
@Repository
public abstract class BaseDao{
	
	 @Autowired
	 private SqlSession sqlSession;
	
	 public BaseDao() {
		super();
	 }
	 
	 public SqlSession getSqlSession() {
		return sqlSession;
	 }

	 public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	 }

	 /**
	  * 防止sql注入
	  */
	 public String transactSqlInject(String str)
	 {
	     return str.replaceAll(".*([';]+|(--)+).*", " ");
	 }
	 
	 public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		 for(int i=0;i<30;i++){
			int k=(int) (Math.random()*124);
			 if(k>=49&&k<=58 ||k>=97 &&k <=124){
				 sb.append(Character.toChars(k));
			 }
		 }
		 System.out.println(sb.toString());
	}
	 public String getTimeID(){
		 DateFormat format=new SimpleDateFormat("yyyyMMddHHmmssSSS");
		 String uuid = format.format(System.currentTimeMillis())+new Double(Math.random()*100000).intValue();
		 while(uuid.length()<22){
			 uuid = uuid + "0";
		 }
		 uuid=uuid.substring(2);
		 return uuid ;	
	 } 
}
